<?php 

session_start();

if (!isset($_SESSION['username'])) {

	if ($_POST) {

		// var_dump($_POST);exit;
		$username = !empty($_POST['username']) ? $_POST['username']:false;
		$password = !empty($_POST['password']) ? $_POST['password']:false;

		if (!$username) {
			$error = "请输入用户名";
			echo $error;
		}


		if(!isset($error)){

			$userData = include './user.php';
			// var_dump($userData);exit;
			foreach ($userData as  $value) {
				if (in_array($username, $value)) {
					$user =$value;
				}
			}

			if (!isset($user)) {
				$error = "用户名或者密码不正确";
				echo $error;
			}else{
				if ($user['password']!=$password) {
					$error = "用户名或者密码不正确";
					echo $error;
				}
			}

			if (isset($_POST['yanzheng'])) {
				if (strtolower($_POST['yanzheng'])!=$_SESSION['res_code']) {
					$error = "验证码有误，请重新输入";
					echo $error;
				}
			}

			if (!isset($error)) {
				$_SESSION['username']=$user['username'];
				$message = "登陆成功";
				include './tpl/success.html';
				exit;
			}

		}
		
	}
	include './tpl/login.html';
}
// else{
// 	$message ="你已经登陆";
// 	include './tpl/success.html';
// }

	





 ?>